﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Utilities
{
	internal class CacheEntry
	{
		private readonly bool slidingWindow;
		private DateTime expireDate;
		private readonly object cacheValue;
		private readonly TimeSpan expireTime;

		public CacheEntry(TimeSpan expireTime, bool slidingWindow, object cacheValue)
		{
			this.expireTime = expireTime;
			this.expireDate = DateTime.Now.Add(expireTime);
			this.slidingWindow = slidingWindow;
			this.cacheValue = cacheValue;
		}

		public bool Expired
		{
			get { return DateTime.Now > expireDate; }
		}

		public object GetValue()
		{
			if (slidingWindow)
			{
				expireDate = DateTime.Now.Add(expireTime);
			}

			return cacheValue;
		}
	}
}